package event;

import java.io.DataOutputStream;

/*
 * An individual Event can be part of a larger group of events. Each is interrelated through 
 * packageOffset and packageSize. For example, a file transfer possibly results in many Events 
 * due to the size of the file. Each segment is marked by these two parameters to determine its
 * place in the greater group of events.
 */
public class Event implements Comparable<Event> {

	public static final int DIR_TYPE = 0xFFFF;
	public static final int FIL_TYPE = 0xEFFF;
	public static final int SEARCH_TYPE = 0xDFFF;
	public static final int HOST_TYPE = 0xDFFF;

	public final int type;

	public final long packageOffset; // the number of bytes received so far for
										// the group of Events.
	public final long packageSize; // the total number of bytes in the group of
									// Events.

	public final String parameters;
	public final byte[] message;

	private final DataOutputStream mDos;

	public Event(int type, String parameters) {
		this(type, parameters, null, 0, 0, null);
	}

	public Event(int type, String parameters, byte[] message) {
		this(type, parameters, message, 0, message.length, null);
	}

	public Event(int type, String parameters, byte[] message,
			long packageOffset, long packageSize, DataOutputStream os) {
		this.type = type;
		this.parameters = parameters;
		this.message = message;

		this.packageOffset = packageOffset;
		this.packageSize = packageSize;

		this.mDos = os;
	}

	public DataOutputStream getOutputStream() {
		return mDos;
	}

	@Override
	public int compareTo(Event e) {
		if (packageOffset < e.packageOffset) {
			return -1;
		} else if (packageOffset == e.packageOffset) {
			return 0;
		} else {
			return 1;
		}
	}

}
